/*
 * caidat.cpp
 *
 *  Created on: Sep 30, 2014
 *      Author: tanpro
 */
#include "file.h"
void nhapkhongtrung(int **a,int &c,int &d)
{
	cout<<"nhap vao mang khong trung\n";
	int t;
	bool r;
	cout<<"nhap vao c";cin>>c;

	cout<<"nhap vao d";cin>>d;



	srand(unsigned(time(0)));
	for(int i=0;i<c;i++)
	{
		*(a+i)=(int *)malloc(100*sizeof(int));
	}
	for(int i = 0; i <c; i++)
	{
		for(int j=0;j<d;j++)
		{
			do
			{
				t = rand()%100;
				r=kiemtra(a,c,d,t);
				if(r==true)
				{
					*(*(a+i)+j) = t;
				}
			}while(r==false);
		}
	}
	cout<<"\n---------------------------------------------------------\n";
}
bool kiemtra(int **a,int c,int d,int t)
{
	for(int i = 0; i < c ; i++)
		for(int j = 0 ; j < d ; j++)
		{
			if(t == *(*(a+i)+j))
				return false;
		}
		return true;
}
void xuat (int **a,int c,int d)
{
	for(int i=0;i<c;i++)
	{
		for(int j=0;j<d;j++)
		{
			cout<<" "<<*(*(a+i)+j);
		}
		cout<<"\n";
	}

	cout<<"\n-------------------------------------------------------------------\n";
}

void mangtangtptd(int **a,int &c,int &d)
{
	srand(unsigned(time(0)));
	for(int i=0;i<c*d;i++)
	{
		for(int j=0;j<c*d;j++)
		{
			if(*(*(a+i/c)+i%d)>*(*(a+j/c)+j%d))
			{
				hoanvi(*(*(a+i/c)+i%d),*(*(a+j/c)+j%d));
			}
		}
	}
	xuat(a,c,d);
	cout<<"\n---------------------------------------------------------\n";
}
void hoanvi(int &l,int  &t)
{
	int k=l;
	l=t;
	t=k;
}
void nhapmangcon(int **p,int &j,int &k)
{
	cout<<"nhap vao mang con\n";
	cout<<"nhap vao j";cin>>j;
	cout<<"nhap vao k";cin>>k;
	cout<<"\n------------------------------------------------------------\n";
	srand(unsigned(time(0)));
	for(int i=0;i<j;i++)
		{
			*(p+i)=(int *)malloc(100*sizeof(int));
		}
	for(int i=0;i<j;i++)
	{
		for(int l=0;l<k;l++)
		{
			printf("*(*(a+%d)%d)",i,l);cin>>*(*(p+i)+l);
		}
	}

}
void xuatmangcon(int **p,int j,int k)
{


	for(int i=0;i<j;i++)
	{
		for(int l=0;l<k;l++)
		{
			cout<<" "<<*(*(p+i)+l);
		}
		cout<<"\n";
	}
	cout<<"\n-----------------------------------------------------------\n";
}
void kiemtramangcon(int **a,int **p,int j,int k,int c,int d)
{

	int dem=0;
		for(int e=0;e<j;e++)
		{
			for(int f=0;f<k;f++)
			{
				for(int i=0;i<c;i++)
					for(int l=0;l<d;l++)
					{
						if(*(*(p+e)+f)==*(*(a+i)+l))
						dem++;

					}
			}
		}
	if(dem==k*j)
	{
		cout<<"la mang con"<<"1";
	}
	else cout<<"0"<<"khong la mang con";
}
